package com.asiainfo.indb.control.db.impl;

import com.asiainfo.indb.control.LogService;
import com.asiainfo.indb.control.db.FileLineInDb;
import com.asiainfo.indb.control.db.IDialect;
import com.asiainfo.indb.control.db.OracleBatchFileLineInDb;
import com.asiainfo.indb.model.DbType;
import com.asiainfo.indb.model.InDbGather;

/**
 * @author zym
 * @date 2019-10-18 13:05
 */
public class OracleDialect implements IDialect {
    @Override
    public String getDialectName() {
        return DbType.DB_ORACLE;
    }

    @Override
    public String getColsSQL(String tableName) {
        return "select * from " + tableName + " where 1=2";
    }

    @Override
    public String getDriverClass() {
        return "oracle.jdbc.OracleDriver";
    }

    @Override
    public FileLineInDb getFileLineInDb(InDbGather gather, LogService log) {
        return new OracleBatchFileLineInDb(gather, log);
    }

    @Override
    public String getInsertSQL(String tb, String[] cols, boolean batch) {
        StringBuilder keys = new StringBuilder();
        StringBuilder values = new StringBuilder();
        keys.append("insert into ")
                .append(tb)
                .append(" (");
        values.append("values (");

        boolean first = true;
        for (String col : cols) {
            if (first) {
                first = false;
            } else {
                keys.append(", ");
                values.append(", ");
            }

            keys.append(col);
            values.append("?");
        }

        keys.append(") ");
        values.append(") ");

        return keys.toString() + values.toString();
    }
}